
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :Jackey
	CreateTime:2008-02-15 17:17:01
*/
public class UserMenuinfoSrv extends IHandler
{

	public UserMenuinfoSrv() 
	{
		super();
	}
	private void deleteUserMenuinfo(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		UserMenuinfo obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = UserMenuinfo.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveUserMenuinfo(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		UserMenuinfo obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = UserMenuinfo.fetch();
    	}
    	else                     //update
    	{
    		obj = UserMenuinfo.fetch(con,id);
    	}
		UserMenuinfoPageData data = (UserMenuinfoPageData)PageData.fromForm(context,UserMenuinfoPageData.class);
		context.setValue("UserMenuinfoPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listUserMenuinfo(DBConnection con,SrvContext context,String path) throws Exception
	{
		UserMenuinfoSearchEvent event = (UserMenuinfoSearchEvent)SearchEvent.fromForm(context,UserMenuinfoSearchEvent.class);
		context.setSessionValue("UserMenuinfoSearchEvent",event);
		context.setNextUrl(path+"UserMenuinfoList.jsp");
	}
	private void backUserMenuinfo(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"UserMenuinfoList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listUserMenuinfo"))
		{
			listUserMenuinfo(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewUserMenuinfo"))
		{
			String id = context.getString("Id",null);
			UserMenuinfo obj = UserMenuinfo.fetch(con,id);
			context.setValue("UserMenuinfo",obj);
			context.setNextUrl(path+"UserMenuinfoView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteUserMenuinfo"))
		{
			context.setErrorUrl(path+"UserMenuinfoList.jsp");
			deleteUserMenuinfo(con,context);
			backUserMenuinfo(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddUserMenuinfo"))
		{
			UserMenuinfo obj = UserMenuinfo.fetch();
			UserMenuinfoPageData data = (UserMenuinfoPageData)PageData.fromTable(obj,UserMenuinfoPageData.class);
			context.setValue("UserMenuinfoPageData",data);
			context.setNextUrl(path+"UserMenuinfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateUserMenuinfo"))
		{
			String id = context.getString("Id",null);
			UserMenuinfo obj = UserMenuinfo.fetch(con,id);
			UserMenuinfoPageData data = (UserMenuinfoPageData)PageData.fromTable(obj,UserMenuinfoPageData.class);
			context.setValue("UserMenuinfoPageData",data);
			context.setNextUrl(path+"UserMenuinfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyUserMenuinfo"))
		{
			String id = context.getString("Id",null);
			UserMenuinfo obj = UserMenuinfo.copy(UserMenuinfo.fetch(con,id));
			UserMenuinfoPageData data = (UserMenuinfoPageData)PageData.fromTable(obj,UserMenuinfoPageData.class);
			context.setValue("UserMenuinfoPageData",data);
			context.setNextUrl(path+"UserMenuinfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveUserMenuinfo"))
		{
			context.setErrorUrl(path+"UserMenuinfoEdit.jsp");
			saveUserMenuinfo(con,context,loginContext);
			backUserMenuinfo(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewUserMenuinfo"))
		{
			context.setErrorUrl(path+"UserMenuinfoEdit.jsp");
			saveUserMenuinfo(con,context,loginContext);
			UserMenuinfo obj = UserMenuinfo.fetch();
			UserMenuinfoPageData data = (UserMenuinfoPageData)PageData.fromTable(obj,UserMenuinfoPageData.class);
			context.setValue("UserMenuinfoPageData",data);
			context.setNextUrl(path+"UserMenuinfoEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListUserMenuinfo"))
		{
			backUserMenuinfo(con,context,path);
			return;
		}
		
		//add by Jackey start

		//add by Jackey end

		Logger.throwException("UserMenuinfoSrv","unknown action_code="+action_code);
	}
}
